package com.singzi.leetcode.N100;

public class T0058 {
    public static void main(String[] args) {
        Solution0058 solution0058 = new Solution0058();
        String s = " ";
        System.out.println(solution0058.lengthOfLastWord(s));

    }
}
class Solution0058 {
    public int lengthOfLastWord(String s) {
        int n = s.length();
        if(n == 0) return 0;
        int flag = 1;
        for(int i = n-1;i>=0;i--){
            if(s.charAt(n-1)==' ') {
                n = n-1;
            }
            else{

                if(s.charAt(i)==' ') return n-i-1;
            }

        }
        return s.length();


    }
}